home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Programming / AmigaE / Src / Rkrm / Graphics_Libraries / Sprites_Bobs / bob.e < prev    next >
Encoding:
Text File  |  1995-09-20  |  4.0 KB  |  125 lines

  1. -> bob.e - Simple Bob example
  2.  
  3. ->>> Header (globals)
  4. OPT PREPROCESS
  5.  
  6. MODULE 'dos/dos',
  7.        'exec/memory',
  8.        'exec/ports',
  9.        'graphics/gels',
  10.        'intuition/intuition',
  11.        'intuition/screens',
  12.        '*animtools'
  13.  
  14. ENUM ERR_NONE, ERR_KICK, ERR_WIN
  15.  
  16. RAISE ERR_KICK IF KickVersion()=FALSE,
  17.       ERR_WIN  IF OpenWindow()=NIL
  18.  
  19. CONST GEL_SIZE=4
  20.  
  21. DEF bob_data1, bob_data2, myNewBob:PTR TO newBob
  22. ->>>
  23.  
  24. ->>> PROC bobDrawGList(rport, vport)
  25. -> Draw the Bobs into the RastPort.
  26. PROC bobDrawGList(rport, vport)
  27.   SortGList(rport)
  28.   DrawGList(rport, vport)
  29.   -> If the GelsList includes true VSprites, MrgCop() and LoadView() here
  30.   WaitTOF()
  31. ENDPROC
  32. ->>> 
  33.  
  34. ->>> PROC process_window(win:PTR TO window, myBob:PTR TO bob)
  35. -> Process window and dynamically change bob:  Get messages.  Go away on
  36. -> IDCMP_CLOSEWINDOW.  Update and redisplay bob on IDCMP_INTUITICKS.  Wait for
  37. -> more messages.
  38. PROC process_window(win:PTR TO window, myBob:PTR TO bob)
  39.   DEF msg:PTR TO intuimessage
  40.   LOOP
  41.     Wait(Shl(1, win.userport.sigbit))
  42.     WHILE msg:=GetMsg(win.userport)
  43.       -> Only IDCMP_CLOSEWINDOW AND IDCMP_INTUITICKS are active
  44.       IF msg.class=IDCMP_CLOSEWINDOW
  45.         ReplyMsg(msg)
  46.         RETURN
  47.       ENDIF
  48.       -> Must be IDCMP_INTUITICKS: change x and y values on the fly.  Note: do
  49.       -> not have to add window offset, Bob is relative to the window (sprite
  50.       -> relative to screen).
  51.       myBob.bobvsprite.x:=msg.mousex+20
  52.       myBob.bobvsprite.y:=msg.mousey+1
  53.       ReplyMsg(msg)
  54.     ENDWHILE
  55.     -> After getting a message, change image data on the fly
  56.     myBob.bobvsprite.imagedata:=IF myBob.bobvsprite.imagedata=bob_data1 THEN
  57.                                   bob_data2 ELSE bob_data1
  58.     InitMasks(myBob.bobvsprite)  -> Set up masks for new image
  59.     bobDrawGList(win.rport, ViewPortAddress(win))
  60.   ENDLOOP
  61. ENDPROC
  62. ->>>
  63.  
  64. ->>> PROC do_Bob(win:PTR TO window)
  65. -> Working with the Bob: setup the GEL system, and get a new Bob (makeBob()). 
  66. -> Add the bob to the system and display.  Use the Bob.  When done, remove the
  67. -> Bob and update the display without the bob.  Cleanup everything.
  68. PROC do_Bob(win:PTR TO window) HANDLE
  69.   DEF myBob=NIL, my_ginfo=NIL
  70.   my_ginfo:=setupGelSys(win.rport, $03)
  71.   myBob:=makeBob(myNewBob)
  72.   AddBob(myBob, win.rport)
  73.   bobDrawGList(win.rport, ViewPortAddress(win))
  74.   process_window(win, myBob)
  75.   RemBob(myBob)
  76.   bobDrawGList(win.rport, ViewPortAddress(win))
  77. EXCEPT DO
  78.   IF myBob THEN freeBob(myBob, myNewBob.rasDepth)
  79.   IF my_ginfo THEN cleanupGelSys(my_ginfo, win.rport)
  80.   ReThrow()
  81. ENDPROC
  82. ->>>
  83.  
  84. ->>> PROC main()
  85. PROC main() HANDLE
  86.   DEF win=NIL
  87.   KickVersion(37)
  88.   -> E-Note: set-up global data
  89.   -> Bob data - two sets that are alternated between.  Note that this data is
  90.   -> at the resolution of the screen.
  91.   bob_data1:=copyListToChip([$FFFF0003, $FFF00003, $FFF00003, $FFFF0003,
  92.                              $3FFFFFFC, $3FF00FFC, $3FF00FFC, $3FFFFFFC])
  93.   bob_data2:=copyListToChip([$C000FFFF, $C0000FFF, $C0000FFF, $C000FFFF,
  94.                              $3FFFFFFC, $3FF00FFC, $3FF00FFC, $3FFFFFFC])
  95.   -> Data for the new Bob object defined in animtools.m
  96.   myNewBob:=[bob_data2, 2, GEL_SIZE,
  97.              2, 3, 0, VSF_SAVEBACK OR VSF_OVERLAY,
  98.              0, 8, 160, 100, 0, 0]:newBob
  99.   win:=OpenWindow([80, 20, 400, 150, -1, -1,
  100.                    IDCMP_CLOSEWINDOW OR IDCMP_INTUITICKS,
  101.                    WFLG_ACTIVATE OR WFLG_CLOSEGADGET OR WFLG_DEPTHGADGET OR
  102.                      WFLG_RMBTRAP,
  103.                    NIL, NIL, 'Bob', NIL, NIL, 0, 0, 0, 0, WBENCHSCREEN]:nw)
  104.   do_Bob(win)
  105. EXCEPT DO
  106.   IF win THEN CloseWindow(win)
  107.   SELECT exception
  108.   CASE ERR_KICK; WriteF('Error: requires V37\n')
  109.   CASE ERR_WIN;  WriteF('Error: could not open window\n')
  110.   CASE "MEM";    WriteF('Error: ran out of memory\n')
  111.   ENDSELECT
  112. ENDPROC IF exception<>ERR_NONE THEN RETURN_FAIL ELSE RETURN_OK
  113. ->>>
  114.  
  115. ->>> PROC copyListToChip(data)
  116. -> E-Note: get some Chip memory and copy list (quick, since LONG aligned)
  117. PROC copyListToChip(data)
  118.   DEF size, mem
  119.   size:=ListLen(data)*SIZEOF LONG
  120.   mem:=NewM(size, MEMF_CHIP)
  121.   CopyMemQuick(data, mem, size)
  122. ENDPROC mem
  123. ->>>
  124.  
  125.